package com.panda.cn.service.impl.ct;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panda.cn.entity.ct.CtRoleMenuEntity;
import com.panda.cn.mapper.ct.CtRoleMenuMapper;
import com.panda.cn.service.ct.CtRoleMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@DS("sys")
public class CtRoleMenuServiceImpl implements CtRoleMenuService {
    
    @Resource
    private CtRoleMenuMapper ctRoleMenuMapper;
    
    /**
     * 根据角色编码查询绑定的菜单编码
     * @param roleCode
     * @return
     */
    @Override
    public List findMenuCodes(String roleCode) {
        LambdaQueryWrapper<CtRoleMenuEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CtRoleMenuEntity::getRoleCode, roleCode);
        List<CtRoleMenuEntity> ctRoleMenuEntityList = ctRoleMenuMapper.selectList(queryWrapper);
        List<String> resList = new ArrayList<>();
        ctRoleMenuEntityList.stream().forEach(ctRoleMenuEntity -> {
            resList.add(ctRoleMenuEntity.getMenuCode());
        });
        return resList;
    }
    
    
    /**
     * 更新
     * @param params
     */
    @Override
    public void update(CtRoleMenuEntity params) {
    
        ctRoleMenuMapper.updateByDeptCode(params);
        
    }
}
